package thread.disruptor.multi;

import com.lmax.disruptor.WorkHandler;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 消费者
 *
 * @author verlet
 * @date 2020/5/3
 */
public class Consumer implements WorkHandler<Order> {
    private final String consumerId;
    private static final AtomicInteger COUNT = new AtomicInteger(0);

    public Consumer(String consumerId) {
        this.consumerId = consumerId;
    }

    @Override
    public void onEvent(Order order) throws Exception {
        System.out.println(Thread.currentThread().getName() + "  ==>当前消费者: " + this.consumerId + "，消费信息：" + order.getId());
        COUNT.incrementAndGet();
    }

    public static AtomicInteger getCount() {
        return COUNT;
    }
}
